package io.renren.modules.stm.controller;

import java.util.Arrays;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.stm.entity.TeachersEntity;
import io.renren.modules.stm.service.TeachersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;



/**
 * 教师
 *
 * @author jie.xiong
 * @email jaaaad@163.com
 * @date 2020-07-12 21:38:45
 */
@RestController
@RequestMapping("/stm/teachers")
@Api(value = "教师接口",description = "教师接口")
public class TeachersController {
    @Autowired
    private TeachersService teachersService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("stm:teachers:list")
    @ApiOperation(value="查询教师信息", notes="根据参数查询教师信息")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = teachersService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{teacherNo}")
    @RequiresPermissions("stm:teachers:info")
    @ApiOperation(value="查询教师信息", notes="根据教师编号查询教师信息")
    public R info(@PathVariable("teacherNo") Integer teacherNo){
		TeachersEntity teachers = teachersService.getById(teacherNo);

        return R.ok().put("teachers", teachers);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("stm:teachers:save")
    @ApiOperation(value="保存教师信息", notes="保存教师信息")
    public R save(@RequestBody TeachersEntity teachers){
		teachersService.save(teachers);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @RequiresPermissions("stm:teachers:update")
    @ApiOperation(value="更新教师信息", notes="更新教师信息")
    public R update(@RequestBody TeachersEntity teachers){
		teachersService.updateById(teachers);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    @RequiresPermissions("stm:teachers:delete")
    @ApiOperation(value="删除教师信息", notes="根据教师编号删除教师信息")
    public R delete(@RequestBody Integer[] teacherNos){
		teachersService.removeByIds(Arrays.asList(teacherNos));

        return R.ok();
    }

}
